//
//  HJXHeadLinesVC.m
//  Catus
//
//  Created by 晓梦影 on 16/4/22.
//  Copyright © 2016年 黄金星. All rights reserved.
//

#import "HJXHeadLinesVC.h"
#import "HJXBaseTableViewController.h"

#import "YYHttpTool.h"
#import "MJExtension.h"

#import "HJXBaseItem.h"
#import "HJXListItem.h"

@interface HJXHeadLinesVC ()

/** 基本控制器*/
@property (nonatomic, strong) HJXBaseTableViewController *baseTableVC;

@end

static NSString *const ID = @"HeadLines";
@implementation HJXHeadLinesVC

#pragma mark - lifeCycle
- (void)viewDidLoad {
    [super viewDidLoad];
        
  
}

- (void)viewWillAppear:(BOOL)animated
{
    // 获取数据
    /*
     // 1.创建会话管理者
     AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
     // 2.封装参数
     NSDictionary *dict = @{
     @"type":@"JSON"
     };
     
     [manager GET:@"http://3g.mop.com/api/client/subject/top.json" parameters:dict progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
     
     NSLog(@"%@",[responseObject class]);
     
     
     } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
     NSLog(@"获取网络失败");
     }];
     */
    NSDictionary *dict = @{
                           @"type":@"JSON"
                           };
    
    /* http://3g.mop.com/api/client/subject/top.json */
    [YYHttpTool get:@"http://3g.mop.com/api/client/subject/hot.json" params:dict success:^(id responseObj) {
        
        //    NSLog(@"success--%@--%@",[responseObj class],responseObj);
        
        // 字典数组 --> 模型数组
        NSDictionary *dict = responseObj[@"subject"];
        // list数组
        NSArray *list = dict[@"list"];
        
        HJXBaseItem *baseItem = [HJXBaseItem mj_objectWithKeyValues:dict];
        
        // 修改属性名称
        [HJXListItem mj_setupReplacedKeyFromPropertyName:^NSDictionary *{
            
            return @{
                     @"ID":@"id",
                     @"catus_description":@"description"
                     };
        }];
        NSArray *listItem = [HJXListItem mj_objectArrayWithKeyValuesArray:list];
        
        // 传给基本控制器，刷新cell
          self.itemArray = listItem;
//        NSLog(@"%@---%ld",listItem,listItem.count);
        
    } failure:^(NSError *error) {
        NSLog(@"网络请求失败");
    }];

    [super viewWillAppear:animated];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
